<?php
namespace app\admin\model;

use think\Model;
use think\Db;

/**
 * 预警
 * @package app\admin\model
 */
class WarUser extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'war_user';

    public function getList($request)
    {
        $plats = db('bus_platfrom')->column('platfrom','plat_id');
        $channels = db('bus_channel')->column('company_name','channel_id');
        $war_config = $this
            ->alias('war')
            ->field(true)
            // ->join('bus_channel cha','cha.channel_id = war.sms_cid','LEFT')
            ->where('war_id',$request['warid'])
            ->order('user_id , onoff desc , time desc')
            ->paginate($request['limit'], false,['query' => $request])
            ->each(function($item, $key)use($plats,$channels){
                switch ($item->user_type) {
                    case 'PLAT':
                        $item->user_id = '[通道]'.$plats[$item->user_id].$item->user_id;
                        break;
                    case 'CHANNEL':
                        $item->user_id = '[渠道]'.$channels[$item->user_id].$item->user_id;
                        break;

                    default:
                        # code...
                        break;
                }

                if($item->type == 1)
                {
                    $item->amt = '(条数)' . $item->sms_amt;
                }else{
                    $item->amt = '(余额)' . $item->amt;
                }
                switch ($item->isp_host) {
                    case '10086':
                        $item->isp_host = '移动';
                        break;
                    case '10010':
                        $item->isp_host = '联通';
                        break;
                    case '10000':
                        $item->isp_host = '电信';
                        break;

                    default:
                        $item->isp_host = '三网';
                        break;
                }
                switch ($item->onoff) {
                    case '0':
                        $item->onoff_ = '<span class="layui-badge layui-bg-orange">已禁用</span>';
                        break;
                    case '1':
                        $item->onoff_ = '<span class="layui-badge layui-bg-green">已开启</span>';
                        break;

                    default:
                        $item->onoff_ = '';
                        break;
                }

                // $item->sms_plat = '<a href="javascript:;" style="color:blue" onClick="openPlat('.$item->id.')"> 查看('.Db::table('war_plat')->where('war_id',$item->id)->count().') </a>';
            });

            return $war_config->toarray();
    }
}